package com.gzhryc.shared_device.oem.code.place.dao;

import com.gzhryc.jdbc.BaseDao;
import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.Query;
import com.gzhryc.shared_device.oem.code.place.dao.db.PlacePhysicalStore;

import java.sql.SQLException;
import java.util.List;

public class PlacePhysicalStoreDao extends BaseDao<PlacePhysicalStore> {

    public PlacePhysicalStoreDao(String jdbcKey){
        super(jdbcKey);
    }

    public List<Long> findIdsByConditions(Conditions conditions,Integer pageNo,Integer pageLimit) throws SQLException {
        String sql = "SELECT id FROM " + this.tableName;
        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        query.setPageNo(pageNo);
        query.setPageLimit(pageLimit);
        return this.jdbcHelper.findFirstField(query,Long.class);
    }

    public List<Long> findIdsByConditions(Conditions conditions) throws SQLException {
        String sql = "SELECT id FROM " + this.tableName;
        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        return this.jdbcHelper.findFirstField(query,Long.class);
    }

    public List<String> findAreaCodeByConditions(Conditions conditions,Integer pageNo,Integer pageLimit) throws SQLException {
        String sql = "SELECT DISTINCT area_code FROM " + this.tableName;
        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        query.setPageNo(pageNo);
        query.setPageLimit(pageLimit);
        return this.jdbcHelper.findFirstField(query,String.class);
    }
}
